package problem120;

import java.util.List;

//120.三角形最小路径和
//https://leetcode.cn/problems/triangle/?envType=study-plan-v2&envId=top-interview-150

class Solution {
    public int minimumTotal(List<List<Integer>> triangle) {
        int n = triangle.size();
        int[] dp = new int[n+1];
        for(int i = n-1; i>=0; i--) {
            for(int j = 0; j<triangle.get(i).size(); j++) {
                dp[j] = Math.min(dp[j+1], dp[j]) + triangle.get(i).get(j);
            }
        }
        return dp[0];
    }
}